$(function(){
    var userId=getvl("id");
    var type=1;
    if (userId != '') {       
        $.ajax({
            url: urlcore + "/api/user/account2Details?userId="+userId,
            type: "get",
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            success:function(data){
                if (data.success == true) {
                    var da = data.data;
                    var serveType = serveTypeStr(da.user.serveType);
					var headUrl = da.user.headUrl;
					var imgStr1 = '';
	                if (headUrl != null && headUrl != '') {
	                  var imgarr = headUrl.split("***");
	                  $.each(imgarr,function(index,value){
	                  	imgStr1 += "<img style='padding: 5px 5px 5px 5px;' width='250px' height='250px' src='"+value+"'>";
	                  });
	                }
	                $('#headUrl').html(imgStr1);
	                
					var licenseUrl = da.user.licenseUrl;
					var imgStr2 = '';
	                if (licenseUrl != null && licenseUrl != '') {
	                  var imgarr = licenseUrl.split("***");

	                  $.each(imgarr,function(index,value){
	                  	imgStr2 += "<img style='padding: 5px 5px 5px 5px;' width='250px' height='250px' src='"+value+"'>";
	                  });
	                }
	                $('#licenseUrl').html(imgStr2);	                

					var storeUrl = da.user.storeUrl;
					var imgStr3 = '';
	                if (storeUrl != null && storeUrl != '') {
	                  var imgarr = 	storeUrl.split("***");
	                  $.each(imgarr,function(index,value){
	                  	imgStr3 += "<img style='padding: 5px 5px 5px 5px;' width='250px' height='250px' src='"+value+"'>";
	                  });
	                }
	                $('#storeUrl').html(imgStr3);
	                
					var identityFront = da.user.identityFront;
					var imgStr4 = '';
	                if (identityFront != null && identityFront != '') {
	                  var imgarr = 	identityFront.split("***");
	                  $.each(imgarr,function(index,value){
	                  	imgStr4 += "<img style='padding: 5px 5px 5px 5px;' width='250px' height='250px' src='"+value+"'>";
	                  });
	                }
	                $('#identityFront').html(imgStr4);
	                
	             	var identityBack = da.user.identityBack;
					var imgStr5 = '';
	                if (identityBack != null && identityBack != '') {
	                  var imgarr = 	identityBack.split("***");
	                  $.each(imgarr,function(index,value){
	                  	imgStr5 += "<img style='padding: 5px 5px 5px 5px;' width='250px' height='250px' src='"+value+"'>";
	                  });
	                }
	                $('#identityBack').html(imgStr5);
	                	                
	                $('#id').text(da.user.secondId);
	                $('#idCard').text(da.user.idCard);
					$('#shopStartTime').text(da.user.shopStartTime);              
					$('#nickName').text(da.user.nickName);				
					$('#realName').text(da.user.realName);
					$('#phone').text(da.user.phone);
					$('#idPhone').text(da.user.phone);
					$('#idCard').text(da.user.idCard);
					$('#shopStartMoney').text(da.user.shopStartMoney);					
					$('#serveType').text(serveType);
					$('#allMoney').text(da.allMoney);
					$('#depositMoney').text(da.depositMoney);
				    //非已审核无钱包详情
					if(da.user.isRegister!==1){
						$("#money").hide();
					}
					//按钮跳转
					$("#wallet1").attr("href","shop_money.html?shopId="+da.user.id+"&value="+1);
					$("#wallet2").attr("href","shop_money.html?shopId="+da.user.id+"&value="+2);
					$("#wallet3").attr("href","shop_money.html?shopId="+da.user.id+"&value="+3);
					$("#shopaddress").attr("href","shopaddress_list.html?shopId="+da.user.id);
					$("#goodsorder").attr("href","usergoods_list.html?userId="+da.user.id);
					$("#message").attr("href","usernotice_list.html?userId="+da.user.id);
					$("#oldorders").attr("href","userorder_list.html?userId="+da.user.id);
					$("#bank").attr("href","bank_list.html?userId="+da.user.id);
					$("#shopsort").attr("href","shopsort_add.html?userId="+da.user.id);
					$("#update").attr("href","shop_update.html?userId="+da.user.id);
					$("#punish").attr("href","userpunish_list.html?userId="+da.user.id);
                } else if (data.code == 'OVERTIME'){
	                    var thisUrl = window.location.href;
	                    if (thisUrl.indexOf('login.html') <= -1) {
	                        top.window.location.href="login.html";
	                    }
	                } else {
	                    alert(data.msg);
	                }
            },
            error:function() {
                /* Act on the event */
                alert("error");
            }
        });
        
        $.ajax({
            url: urlcore + "/api/sortBetween/shopDetails?userId="+userId+"&type="+type,
            type: "get",
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            success:function(data){
                if (data.success == true) {
                    $.each(data.data,function(i,n){
                      $('#sortName').append(n.sortTypeId.sortName + " ");
                    });
                } else if (data.code == 'OVERTIME'){
	                    var thisUrl = window.location.href;
	                    if (thisUrl.indexOf('login.html') <= -1) {
	                        top.window.location.href="login.html";
	                    }
	                } else {
	                    alert(data.msg);
	                }
            },
            error:function() {
                /* Act on the event */
                alert("error");
            }
        });
        
        $.ajax({
            url: urlcore + "/api/address/addressByUserId?userId="+userId,
            type: "get",
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            success:function(data){
                if (data.success == true) {
                    var da = data.data;
                    $('#address').text(da.province+da.city+da.county);
                    $('#addressDetail').text(da.addressDetail);
                } else if (data.code == 'OVERTIME'){
	                    var thisUrl = window.location.href;
	                    if (thisUrl.indexOf('login.html') <= -1) {
	                        top.window.location.href="login.html";
	                    }
	                } else {
	                    alert(data.msg);
	                }
            },
            error:function() {
                /* Act on the event */
                alert("error");
            }
        });
        
    }

});

/**
 * 用户状态返回
 * @param {Object} serveType
 */
function serveTypeStr(serveType){
	if (serveType==1) {
		serveType = '正常';
	}else if(serveType==2) {
		serveType = '处罚';
	}
	return serveType;
}

